#ifndef _PINCHECKPOINTER_H_
#define _PINCHECKPOINTER_H_
#include "Checkpointer.h"
#include "../Runtime/Recovery.h"
#include <map>
#include <vector>

class PinCheckpointer : public Checkpointer{

public:

  /*A variable that tells our checkpointing function whether
    to capture a new checkpoint or to resume from the existing
    one*/
  bool resumingFromCheckPoint;

  unsigned activeCheckpoint;

  Checkpoint *currentCheckPoint;
  map<unsigned, Checkpoint *> namedCheckpoints;

  map<unsigned, Recovery *> recoveryRecords;
  map<unsigned, void(*)(Recovery *)> recoveryRoutines;

  /*Max observed stack size in this execution.  Conservatively copy stack of 
    this many bytes on checkpoint*/
  unsigned long maxStack;

  PinCheckpointer(vector< void(*)(Recovery *) > *v);

  void setActiveCheckpoint( unsigned name );
  unsigned getActiveCheckpoint( );  
  Checkpoint *getCP(unsigned name);
 

};

VOID RestoreCheckPoint(ADDRINT name);
VOID CaptureCheckPoint(CONTEXT *ctx, ADDRINT name, Recovery *r);
void initCheckpointer(vector< void(*)(Recovery *) > *v);
VOID checkpointerInstrumentTrace(TRACE trace, VOID *v);
#endif
